package com.offset;

import kafka.producer.KeyedMessage;
import kafka.javaapi.producer.Producer;
import kafka.producer.ProducerConfig;
import scala.collection.Seq;

import java.util.Properties;
import java.util.UUID;

public class KafakaProducerApp {

    public static void main(String[] args) {
        String topic = "hello_topic";

        Properties properties = new Properties();
        properties.put("metadata.broker.list", "hadoop000:9092");
        properties.put("serializer.class","kafka.serializer.StringEncoder");
        properties.put("request.required.acks","1");
        properties.put("partitioner.class","kafka.producer.DefaultPartitioner");

        Producer<Object, Object> producer
                = new Producer<>(new ProducerConfig(properties));

        for (int i = 0; i < 100; i++) {

            producer.send(new KeyedMessage<>(topic,i+"  ", UUID.randomUUID().toString()));

        }

        System.out.println("kafka producer 数据产生完毕");
    }

}
